// 提现输入框
<template>
    <div>
        <div class="putforwardBox">
            <GoBack></GoBack>
            <p class="adselfBox">收益提现</p>
            <NoCard v-show='isNoCard'></NoCard>
            <div class="putforwarCont" v-show='!isNoCard'>
                <div class="selcetBox flex flex-align-center">
                 <p>到账银行卡</p>
                 <select name="" class="select" @change="onChangeFun">
                     <option :value="item.id" v-for="(item,index) in options" :key='index'>{{item.title}}({{item.last_number}})</option>
                 </select>
                </div>
                <div class="tixianBox flex">
                    <p>提现金额</p>
                    <div class="inputBox">
                        <div class="moneyBox flex flex-align-center">
                            <span>￥</span>
                            <input type="text" placeholder="0.00" class="input-money" v-model.trim='Num'>
                            <div class="qb-btn" @click="onAllBtnFun">全部提现</div>
                        </div>
                        <p class="tips">最低提现100元，当前可提现金额：<span>￥{{balance}}</span> </p>
                    </div>
                </div>
                <!-- 提现按钮 -->
                <div class="txBtn flex flex-align-center flex flex-pack-center" @click="postNum"><p>确认提现</p></div>
                <!-- 底部提示 -->
                <div class="txBox-buttom">
                    <p>温馨提示：1、提现受理成功后，T+1工作日到账，具体到账时间视结算卡银行而定，超过24小时请联系我们，客服QQ:{{QQNum}}。2、最低提现金额为100元。</p>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import GoBack from '../goback'
import NoCard from './assembly/nobankcard'
import https from '@/public/https'
import { setTimeout } from 'timers';
export default {
components: {
    GoBack,
    NoCard
},
mounted () {
    this.getBankCardlist();
    this.getServce();
},
data () {
    return {
        options:[],
        isNoCard:false,
        bankCardId:'',
        Num:'',
        QQNum:'',
    }
},
computed: {
    balance(){
        return this.$store.getters.getUserInfo.balance;
    }
},
methods: {
    getBankCardlist(){
         let uid = this.$store.state.userInfo.id;
        this.https('user/getObtainUserBankById',{uid:uid})
        .then(data => {
            if(data.list.length == 0){
               this.isNoCard = true; 
            }
            this.bankCardId = data.list[0].id;
            this.options = data.list;
        })
    },
    onChangeFun(ele){ //选取银行卡
        this.bankCardId = ele.target.value;
    },
    onAllBtnFun(){ //全部提现
        this.Num = this.$store.state.userInfo.balance;
    },
    postNum(){
        let uid = this.$store.state.userInfo.id;
        if(Number(this.Num) <= Number(this.$store.state.userInfo.balance)){
            if(this.Num != '' && this.bankCardId !=''){
                if(Number(this.Num)>=Number(100)){
                       https.post('user/postAddUserCash',{
                        uid:uid,
                        bankcard_id:this.bankCardId,
                        money:this.Num*100
                    })
                    .then(data => {
                        if(data.status){
                           this.$toast({
                                    message:'提现成功'
                            });
                            let balance = this.$store.state.userInfo.balance - this.Num; //剩余余额
                            balance =  balance.toFixed(2);
                            this.$store.commit('setBalance',balance); //修改余额
                        }else{
                            this.$toast({message:data.message});
                        }
                    })
                }else{
                    this.$toast({message:'最少提现金额为100元'});
                }
            }
        }else{
            this.$toast({message:'超出可提现金额，请重新输入'});
        }
    },
    getServce(){
        this.https('common/getObtainOnlineNumber')
        .then(data => {
            this.QQNum = data.server_qq;
        })
    }
}
}
</script>
<style lang="less" scoped>
@import url(../../assets/css/usercenter/putforward.less);
</style>


